Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[computer use] replace spaces in api_key when starting loop #90

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

bmacer
Copy link
Contributor

@bmacer bmacer commented Oct 23, 2024

this addresses #85.

it would seem that if multiple users have already encountered this, maybe the propensity to copy-paste with a trailing space is common enough to address.

maybe not the most graceful solution, just replaces all spaces when the sampling_loop begins.

prior to the fix, here's the error when i use an API key with a trailing space:

image

after the fix, no problem, even with a trailing space:

image

@bmacer bmacer requested a review from x5a October 25, 2024 14:53
@marco-altran
Copy link

I can still reproduce #85 after your fix (yes, I applied your fix and did the build locally).

I also experimented with disabling the cache prompt and increasing image_truncation_threshold. The issue takes longer to appear, but eventually, after a minute, the error persists. I hardcoded the API key, and nothing changed, so I am ruling out API key issues.

My hunch is either malformation of messages or the Anthropic API not handling a specific situation.

Stack trace:

File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/httpx/_transports/default.py", line 72, in map_httpcore_exceptions
    yield

  File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/httpx/_transports/default.py", line 236, in handle_request
    resp = self._pool.handle_request(req)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/httpcore/_sync/connection_pool.py", line 216, in handle_request
    raise exc from None

  File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/httpcore/_sync/connection_pool.py", line 196, in handle_request
    response = connection.handle_request(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/httpcore/_sync/connection.py", line 101, in handle_request
    return self._connection.handle_request(request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/httpcore/_sync/http11.py", line 143, in handle_request
    raise exc

  File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/httpcore/_sync/http11.py", line 113, in handle_request
    ) = self._receive_response_headers(**kwargs)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/httpcore/_sync/http11.py", line 186, in _receive_response_headers
    event = self._receive_event(timeout=timeout)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/httpcore/_sync/http11.py", line 224, in _receive_event
    data = self._network_stream.read(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/httpcore/_backends/sync.py", line 124, in read
    with map_exceptions(exc_map):

  File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/contextlib.py", line 155, in __exit__
    self.gen.throw(typ, value, traceback)

  File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/httpcore/_exceptions.py", line 14, in map_exceptions
    raise to_exc(exc) from exc

httpcore.ReadError: [SSL: SSLV3_ALERT_BAD_RECORD_MAC] sslv3 alert bad record mac (_ssl.c:2580)


The above exception was the direct cause of the following exception:


Traceback (most recent call last):

  File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/anthropic/_base_client.py", line 990, in _request
    response = self._client.send(
               ^^^^^^^^^^^^^^^^^^

  File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/httpx/_client.py", line 926, in send
    response = self._send_handling_auth(
               ^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/httpx/_client.py", line 954, in _send_handling_auth
    response = self._send_handling_redirects(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/httpx/_client.py", line 991, in _send_handling_redirects
    response = self._send_single_request(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/httpx/_client.py", line 1027, in _send_single_request
    response = transport.handle_request(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/httpx/_transports/default.py", line 235, in handle_request
    with map_httpcore_exceptions():

  File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/contextlib.py", line 155, in __exit__
    self.gen.throw(typ, value, traceback)

  File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/httpx/_transports/default.py", line 89, in map_httpcore_exceptions
    raise mapped_exc(message) from exc

httpx.ReadError: [SSL: SSLV3_ALERT_BAD_RECORD_MAC] sslv3 alert bad record mac (_ssl.c:2580)


The above exception was the direct cause of the following exception:


Traceback (most recent call last):

  File "/home/computeruse/computer_use_demo/loop.py", line 132, in sampling_loop
    raw_response = client.beta.messages.with_raw_response.create(
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/anthropic/_legacy_response.py", line 377, in wrapped
    return cast(LegacyAPIResponse[R], func(*args, **kwargs))
                                      ^^^^^^^^^^^^^^^^^^^^^

  File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/anthropic/_utils/_utils.py", line 274, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^

  File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/anthropic/resources/beta/messages/messages.py", line 896, in create
    return self._post(
           ^^^^^^^^^^^

  File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/anthropic/_base_client.py", line 1277, in post
    return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/anthropic/_base_client.py", line 954, in request
    return self._request(
           ^^^^^^^^^^^^^^

  File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/anthropic/_base_client.py", line 1014, in _request
    return self._retry_request(
           ^^^^^^^^^^^^^^^^^^^^

  File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/anthropic/_base_client.py", line 1092, in _retry_request
    return self._request(
           ^^^^^^^^^^^^^^

  File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/anthropic/_base_client.py", line 1014, in _request
    return self._retry_request(
           ^^^^^^^^^^^^^^^^^^^^

  File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/anthropic/_base_client.py", line 1092, in _retry_request
    return self._request(
           ^^^^^^^^^^^^^^

  File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/anthropic/_base_client.py", line 1024, in _request
    raise APIConnectionError(request=request) from err

anthropic.APIConnectionError: Connection error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants